package com.college.products.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.college.common.pojo.ao.Order;
import com.college.common.pojo.dto.products.AddOrderDTO;
import com.college.common.pojo.dto.products.QueryOrderDTO;
import com.college.common.pojo.dto.products.UpdateOrderDTO;
import com.college.common.pojo.model.page.PageParamRequest;
import com.college.common.response.CommonResult;
import com.college.common.utils.object.ObjectUtil;
import com.college.products.mapper.OrderMapper;
import com.college.products.service.OrderService;
import com.github.pagehelper.page.PageMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 订单 服务实现类
 * @author 小C工作室
 * @since 2025-02-22
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List<Order> queryList(QueryOrderDTO queryOrderDTO) {
        return orderMapper.queryList(queryOrderDTO);
    }

    @Override
    public List<Order> queryListPage(QueryOrderDTO queryOrderDTO, PageParamRequest pageParamRequest) {
        PageMethod.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        return orderMapper.queryList(queryOrderDTO);
    }

    @Override
    public CommonResult<String> addOrder(AddOrderDTO addOrderDTO) {
        return this.save(addOrderDTO)? CommonResult.success("订单新增成功") : CommonResult.failed("订单新增失败");
    }

    @Override
    public CommonResult<String> updateOrder(UpdateOrderDTO updateOrderDTO) {
        Order order = ObjectUtil.objectCopyProperties(updateOrderDTO, Order.class);
        return this.updateById(order) ? CommonResult.success("订单修改成功") : CommonResult.failed("订单修改失败");
    }
}
